/* 
* Reducer funtion
*/

interface InitialState {
    count: number;
}
type ActionType = {
    type: 'increment';
    payload: number;
} | {
    type: 'decrement';
    payload: string;
} | {
    type: 'initial'
};

export const initialState: InitialState = { count: 0 };
function reducer(state: InitialState, action: ActionType) {
    switch (action.type) {
        case 'increment':
            return { count: state.count + action.payload };
        case 'decrement':
            return { count: state.count - Number(action.payload) };
        case 'initial':
            return state;
        default:
            throw new Error();
    }
}

export type { ActionType, InitialState };
export default reducer;